home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / TreeSelectionModel.java < prev    next >
Text File  |  1998-06-30  |  7KB  |  229 lines

  1. /*
  2.  * @(#)TreeSelectionModel.java    1.8 97/09/30
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.tree;
  22.  
  23. import com.sun.java.swing.event.*;
  24. import java.beans.PropertyChangeListener;
  25.  
  26. /**
  27.   * This interface represents the current state of the selection for
  28.   * the tree component.  It will keep track of the selected rows, but
  29.   * in order to select by row you will need to go directly to the tree.
  30.   *
  31.   * @version 1.8 09/30/97
  32.   * @author Scott Violet
  33.   */
  34.  
  35. public interface TreeSelectionModel
  36. {
  37.     /** Selection can only contain one path at a time. */
  38.     public static int               SINGLE_TREE_SELECTION = 1;
  39.  
  40.     /** Selection can only be contiguous. This will only be enforced if
  41.      * a RowMapper instance is provided. */
  42.     public static int               CONTIGUOUS_TREE_SELECTION = 2;
  43.  
  44.     /** Selection can contain any number of items that are not necessarily
  45.      * contiguous. */
  46.     public static int               DISCONTIGUOUS_TREE_SELECTION = 4;
  47.  
  48.     /**
  49.      * Sets the selection model, which must be one of SINGLE_TREE_SELECTION,
  50.      * CONTIGUOUS_TREE_SELECTION or DISCONTIGUOUS_TREE_SELECTION.
  51.      */
  52.     void setSelectionMode(int mode);
  53.  
  54.     /**
  55.      * Returns the selection mode.
  56.      */
  57.     int getSelectionMode();
  58.  
  59.     /**
  60.       * Sets the selection to path.  If this represents a change, then
  61.       * the TreeSelectionListeners are notified.
  62.       *
  63.       * @param path new path to select
  64.       */
  65.     void setSelectionPath(TreePath path);
  66.  
  67.     /**
  68.       * Sets the selection to the the paths.  If this represents a
  69.       * change the TreeSelectionListeners are notified.
  70.       *
  71.       * @param paths new selection.
  72.       */
  73.     void setSelectionPaths(TreePath[] paths);
  74.  
  75.     /**
  76.       * Adds path to the current selection.  If path is not currently
  77.       * in the selection the TreeSelectionListeners are notified.
  78.       *
  79.       * @param path the new path to add to the current selection.
  80.       */
  81.     void addSelectionPath(TreePath path);
  82.  
  83.     /**
  84.       * Adds paths to the current selection.  If any of the paths in 
  85.       * paths are not currently in the selection the TreeSelectionListeners
  86.       * are notified.
  87.       *
  88.       * @param path the new path to add to the current selection.
  89.       */
  90.     void addSelectionPaths(TreePath[] paths);
  91.  
  92.     /**
  93.       * Removes path from the selection.  If path is in the selection
  94.       * The TreeSelectionListeners are notified.
  95.       *
  96.       * @param path the path to remove from the selection.
  97.       */
  98.     void removeSelectionPath(TreePath path);
  99.  
  100.     /**
  101.       * Removes paths from the selection.  If any of the paths in paths
  102.       * are in the selection the TreeSelectionListeners are notified.
  103.       *
  104.       * @param path the path to remove from the selection.
  105.       */
  106.     void removeSelectionPaths(TreePath[] paths);
  107.  
  108.     /**
  109.       * Returns the first path in the selection.
  110.       */
  111.     TreePath getSelectionPath();
  112.  
  113.     /**
  114.       * Returns the paths in the selection.
  115.       */
  116.     TreePath[] getSelectionPaths();
  117.  
  118.     /**
  119.      * Returns the number of paths that are selected.
  120.      */
  121.     int getSelectionCount();
  122.  
  123.     /**
  124.       * Returns true if the path, path, is in the current selection.
  125.       */
  126.     boolean isPathSelected(TreePath path);
  127.  
  128.     /**
  129.       * Returns true if the selection is currently empty.
  130.       */
  131.     boolean isSelectionEmpty();
  132.  
  133.     /**
  134.       * Empties the current selection.  If this represents a change in the
  135.       * current selection, the selection listeners are notified.
  136.       */
  137.     void clearSelection();
  138.  
  139.     /**
  140.      * Sets the RowMapper instance.  This instance is used to determine
  141.      * what row corresponds to what path.
  142.      */
  143.     void setRowMapper(RowMapper newMapper);
  144.  
  145.     /**
  146.      * Returns the RowMapper instance that is able to map a path to a
  147.      * row.
  148.      */
  149.     RowMapper getRowMapper();
  150.  
  151.     /**
  152.       * Returns all of the currently selected rows.
  153.       */
  154.     int[] getSelectionRows();
  155.  
  156.     /**
  157.       * Gets the first selected row.
  158.       */
  159.     int getMinSelectionRow();
  160.  
  161.     /**
  162.       * Gets the last selected row.
  163.       */
  164.     int getMaxSelectionRow();
  165.  
  166.     /**
  167.       * Returns true if the row identitifed by row is selected.
  168.       */
  169.     boolean isRowSelected(int row);
  170.  
  171.     /**
  172.      * Updates what rows are selected.  This can be externally called in
  173.      * case the location of the paths change, but not the actual paths.
  174.      * You do not normally need to call this.
  175.      */
  176.     void resetRowSelection();
  177.  
  178.     /**
  179.      * Returns the lead selection index. That is the last index that was
  180.      * added.
  181.      */
  182.     int getLeadSelectionRow();
  183.  
  184.     /**
  185.      * Returns the last path that was added.
  186.      */
  187.     TreePath getLeadSelectionPath();
  188.  
  189.     /**
  190.      * Add a PropertyChangeListener to the listener list.
  191.      * The listener is registered for all properties.
  192.      * <p>
  193.      * A PropertyChangeEvent will get fired in response to an
  194.      * explicit setFont, setBackground, or SetForeground on the
  195.      * current component.  Note that if the current component is
  196.      * inheriting its foreground, background, or font from its
  197.      * container, then no event will be fired in response to a
  198.      * change in the inherited property.
  199.      *
  200.      * @param listener  The PropertyChangeListener to be added
  201.      */
  202.     void addPropertyChangeListener(PropertyChangeListener listener);
  203.  
  204.     /**
  205.      * Remove a PropertyChangeListener from the listener list.
  206.      * This removes a PropertyChangeListener that was registered
  207.      * for all properties.
  208.      *
  209.      * @param listener  The PropertyChangeListener to be removed
  210.      */
  211.     void removePropertyChangeListener(PropertyChangeListener listener);
  212.  
  213.     /**
  214.       * Adds x to the list of listeners that are notified each time the
  215.       * selection changes.
  216.       *
  217.       * @param x the new listener to be added.
  218.       */
  219.     void addTreeSelectionListener(TreeSelectionListener x);
  220.  
  221.     /**
  222.       * Removes x from the list of listeners that are notified each time
  223.       * the selection changes.
  224.       *
  225.       * @param x the listener to remove.
  226.       */
  227.     void removeTreeSelectionListener(TreeSelectionListener x);
  228. }
  229.